package com.ease.common.util;

import java.util.List;

import org.springframework.util.ClassUtils;

/**
 * 
 * @author nathanleewei
 * 
 */
public abstract class ConfigurationUtil extends Detect {

	public static <T> List<T> loadListByJsonFile(Class<?> classPackageAsResourcePath, String fileName, Class<T> marshalClass) {
		return loadListByJsonFile(ClassUtils.classPackageAsResourcePath(classPackageAsResourcePath), fileName, marshalClass);
	}

	public static <T> List<T> loadListByJsonFile(String filePath, String fileName, Class<T> marshalClazz) {
		String metaEntityTypeDefinitionString = FileUtil.readClassPathResourceToString(filePath, fileName);
		if (null != metaEntityTypeDefinitionString) {
			return JsonUtil.unmarshalList(metaEntityTypeDefinitionString, marshalClazz);
		}
		return null;
	}

	public static <T> T loadObjectByJsonFile(Class<?> classPackageAsResourcePath, String fileName, Class<T> marshalClass) {
		return loadObjectByJsonFile(ClassUtils.classPackageAsResourcePath(classPackageAsResourcePath), fileName, marshalClass);
	}

	public static <T> T loadObjectByJsonFile(String filePath, String fileName, Class<T> marshalClass) {
		String metaEntityTypeDefinitionString = FileUtil.readClassPathResourceToString(filePath, fileName);
		if (null != metaEntityTypeDefinitionString) {
			return JsonUtil.unmarshal(metaEntityTypeDefinitionString, marshalClass);
		}
		return null;
	}

}
